<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

</body>

</html>
<script>
    (function () {
        function Observer() {
            this.obj = {}
            this.on = function (type, handler) {
                this.obj[type] = this.obj[type] || []
                this.obj[type].push(handler)
            }
            this.emit = function (type, msg) {
                this.obj[type] &&
                    this.obj[type].forEach((item) => {
                        item(msg)
                    })
            }
        }
        window.Observer = Observer
    })()
    var os = new Observer()
    os.on('lijiaqi', function (msg) {
        console.log('莉莉 收到了来自lijiaqi的消息:' + msg);
    })

    os.emit('lijiaqi', '一起来买买买')
</script>